<template>
	<view>
		<uni-list id="news_list" loadmoreoffset="10rpx">
			<uni-list-item v-for="(item, index) in regions" :key="index" :title="item">
			</uni-list-item>
		</uni-list>
		<uni-load-more :status="status"></uni-load-more>
	</view>
</template>

<script>
import uniList from '@/components/uni-list/uni-list.vue';
import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';

var _self;

export default {
	data() {
		return {
			regions: [],
			status: 'noMore',
			page: 0,
			conditions: []
		};
	},
	onLoad() {
		_self = this;
		const regionInfo = uni.getStorageSync('regionInfo');
		this.conditions = uni.getStorageSync('conditions');
		this.regions = regionInfo.records;
		this.page = regionInfo.current;
		this.status = regionInfo.current >= regionInfo.pages ? 'noMore' : 'more';
	},
	onShow() {
		if (this.regions.length === 0) {
			uni.showModal({
				showCancel: false,
				title: '没有哦!',
				content: '请减少一些症状,来提高匹配率!',
				success: (res) => {
					if (res.confirm || res.cancel) {
						uni.navigateBack();
					}
				}
			})
		}
	},
	components: { uniList, uniListItem, uniLoadMore },
	methods: {},
	onReachBottom: function() {	// 监听是否滑倒页面底部，滑到就去加载新的一页新闻列表
		_self.status = 'loading';
		uni.request({
			url: _self.websiteUrl + '/getCtos',	
			method: 'POST',
			header: {
				'content-type': 'application/x-www-form-urlencoded'
			},
			data: {
				"ctos[]": _self.conditions.toString(),
				"size": 25,
				"page": _self.page + 1,
				"token": uni.getStorageSync("token").token,
			},
			success: (t) => {
				const regionInfo = t.data.payload
				_self.regions = _self.regions.concat(regionInfo.records)
				_self.page = regionInfo.current;
				_self.status = regionInfo.current >= regionInfo.pages ? 'noMore' : 'more';
			},
			fail: (t) => {
				_self.status = 'noMore';
				uni.showToast({
					icon: 'none',
					title: '请求失败!'
				})
			}
		})
	}
};
</script>

<style></style>
